#include "MacroTask.h"

#include "Task.h"
#include "..\Util.h"

namespace BroodWar
{
	namespace Addon
	{
		MacroTask^ ConvertMacroTask(BWSAL::MacroTask* task)
		{
			if(task == NULL)
				return nullptr;
			return gcnew MacroTask(task);
		}

		BWSAL::MacroTask* ConvertMacroTask(MacroTask^ task)
		{
			if(task == nullptr)
				return NULL;
			return task->instance;
		}

		MacroTask::MacroTask(BWSAL::MacroTask* task)
		{
			instance = task;
			dispose = false;
		}
		
		MacroTask::~MacroTask()
		{
			if(dispose)
				delete instance;
		}
		
		MacroTask::!MacroTask()
		{
			if(dispose)
				delete instance;
		}
		
		MacroTask::MacroTask(BuildType type, int priority, bool isAdditional, int count)
		{
			instance = new BWSAL::MacroTask(ConvertBuild(type), priority, isAdditional, count);
			dispose = true;
		}
		
		MacroTask::MacroTask(BuildType type, int priority, bool isAdditional, int count, TilePosition^ seedLocation)
		{
			instance = new BWSAL::MacroTask(ConvertBuild(type), priority, isAdditional, count, ConvertTile(seedLocation));
			dispose = true;
		}

		List<Task^>^ MacroTask::Tasks::get()
		{
			return ToList<BWSAL::Task*, Task^>(instance->getTasks(), &ConvertTask);
		}
		
		Build^ MacroTask::Type::get()
		{
			return ConvertBuild(instance->getType());
		}
		
		bool MacroTask::IsAdditional::get()
		{
			return instance->isAdditional();
		}
		
		bool MacroTask::IsCompleted::get()
		{
			return instance->isCompleted();
		}
		
		int MacroTask::Count::get()
		{
			return instance->getCount();
		}
		
		TilePosition^ MacroTask::SeedLocation::get()
		{
			return ConvertTile(instance->getSeedLocation());
		}
		
		int MacroTask::Priority::get()
		{
			return instance->getPriority();
		}
		
		int MacroTask::RemainingCount::get()
		{
			return instance->getRemainingCount();
		}
		
		void MacroTask::RemainingCount::set(int value)
		{
			instance->setRemainingCount(value);
		}

		int MacroTask::WaitingCount::get()
		{
			return instance->getWaitingCount();
		}
		
		int MacroTask::IncompleteCount::get()
		{
			return instance->getIncompleteCount();
		}
		
		int MacroTask::ComputeRemainingCount()	
		{
			return instance->computeRemainingCount();
		}
		
		Task^ MacroTask::NextUnscheduledTask::get()
		{
			return ConvertTask(instance->getNextUnscheduledTask());
		}
	}
}
